package ch3oopexer1;

import java.util.Arrays;
import java.util.Scanner;

/*
* 定义一个字符串数组，输入一个字符串,从数组中删除,删除后,后面的往前移动,注意置空的处理...
比如字符串为{"aa","bb","cc","ff"},如果bb被删除后,则为{"aa","cc","ff",null}*/
public class StringTest {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入数组的长度：");
        int length = scan.nextInt();
        String[] arr = new String[length];
        System.out.println("请输入"+length+"个数组元素：");
        for(int j=0;j<arr.length;j++){
            arr[j]=scan.next();
        }
        System.out.println(Arrays.toString(arr));
        System.out.println("请输入要删除元素的位置(从0开始):");
        int wZNum = scan.nextInt();
        StringTest test = new StringTest();
        test.delete(arr,wZNum);
        System.out.println(Arrays.toString(arr));
    }
    public void delete(String[] arr,int index){
        for(int i=index;i<arr.length-1;i++){
                arr[i]=arr[i+1];


        }
        arr[arr.length-1]=null;//注意这个得用这种写法
    }
}
